package util;

import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.font.FontRenderContext;
import java.awt.geom.Rectangle2D;

public class StringMetrics {

    public static Rectangle2D getBounds(Graphics2D g2d, String message) {
        Font font = g2d.getFont();
        FontRenderContext context = g2d.getFontRenderContext();
        return font.getStringBounds(message, context);
    }

    public static int getWidth(Graphics2D g2d, String message) {
        Rectangle2D bounds = getBounds(g2d, message);
        return (int) bounds.getWidth();
    }

    public static int getHeight(Graphics2D g2d, String message) {
        Rectangle2D bounds = getBounds(g2d, message);
        return (int) bounds.getHeight();
    }

}
